﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using Terrae.Datos.IDaos;
using Terrae.Clases;
using Terrae.Clases.FabricaClase;

namespace Terrae.Datos.DaoSqlServer
{
    public class DaoPlanta : DaoSqlServer, IDaoPlanta
    {
        #region Atributos

        private Conexion bd = new Conexion();
        SqlCommand command = new SqlCommand();
        //private Entidad _miPlanta = null;
        
        #endregion Atributos

        #region Métodos 

        #region Agregar Planta

        /// <summary>
        /// Método que accede a la base de datos para agregar
        /// una planta.
        /// </summary>
        /// <param name="_planta"></param>
        /// <returns></returns>
        public bool AgregarPlanta(Entidad _planta)
        {
            try
            {
                bd.AbrirConexion();
                command.Connection = bd.ObjetoConexion();
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = "[dbo].[INSPlanta]";
                command.CommandTimeout = 10;

                command.Parameters.AddWithValue("@Nombre",
                (_planta as Planta).NombrePlanta);
                command.Parameters.AddWithValue("@Descripcion",
                (_planta as Planta).Descripcion);
                command.Parameters.AddWithValue("@Invernadero",
                (_planta as Planta).Invernadero);

                SqlDataReader readers = command.ExecuteReader();

                readers.Close();
                return true;
            }
            catch (SqlException)
            {
                return false;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                bd.CerrarConexion();
            }
        }

        #endregion Agregar Planta

        #endregion Métodos
    }
}